import request from '@/utils/http'
// ------------------角色管理----------------

interface MenuTree {
  parentId: string
  id: string
  displayName: string
  selectedFlag: any
  code: string
  menuTrees: MenuTree[]
}

interface GetHuoQuYongHuMingChengReslut {
  tenantId: string
  userName: string
  name: string
  surname: any
  email: string
  emailConfirmed: boolean
  phoneNumber: string
  phoneNumberConfirmed: boolean
  lockoutEnabled: boolean
  lockoutEnd: any
  concurrencyStamp: string
  isDeleted: boolean
  deleterId: any
  deletionTime: any
  lastModificationTime: string
  lastModifierId: string
  creationTime: string
  creatorId: string
  id: string
  extraProperties: object
}

// 获取所有角色
export function getRoles() {
  return request.request({
    url: '/api/identity/roles/all',
    method: 'get'
  })
}

// 新增角色
export function postRoles(data) {
  return request.request({
    url: '/api/identity/roles',
    method: 'post',
    data
  })
}

// 修改角色信息
export function putRoles(data) {
  return request.request({
    url: '/api/identity/roles/' + data.id,
    method: 'put',
    data
  })
}

// 删除角色信息
export function deleteRoles(data) {
  return request.request({
    url: '/api/identity/roles/' + data.id,
    method: 'delete'
  })
}

// 获取admin角色所有的菜单tree
export function getAdminMenu(type) {
  return request.request<MenuTree>({
    url: '/api/v3.1/business/menu-units/admin-menu?menuSourceEnum=' + type,
    method: 'get'
  })
}

// 根据角色Id获取已分配的菜单数组-前端
export function getMenuById(id, type) {
  return request.request({
    url:
      '/api/v3.1/business/menu-units/menu-units-by-role?providerKey=' +
      id +
      '&menuSourceEnum=' +
      type +
      '&providerName=R',
    method: 'get'
  })
}

// 修改角色的菜单-前端
export function postMenuById(data) {
  return request.request({
    url: '/api/v3.1/business/menu-units/menu-units-asso-role',
    method: 'post',
    data
  })
}
// 获得工种列表
export function getHuoQuGongZhongList() {
  return request.request({
    url: '/api/v3.0/basic/job-title-record',
    method: 'get'
  })
}
// 根据角色名称，获取用户列表信息
export function getJueSeHuoQuYongHuXinXi(roleName) {
  return request.request({
    url: '/api/identity/GetUsersByRoleNameAsync?roleName=' + roleName,
    method: 'get'
  })
}

// 获得用户名称
export function getHuoQuYongHuMingCheng(id: string) {
  return request.request<GetHuoQuYongHuMingChengReslut>({
    url: '/api/identity/users/' + id,
    method: 'get'
  })
}
